import Vue from 'vue'
import App from './App.vue'
import router from './router'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import 'font-awesome/css/font-awesome.css'
import * as echarts from 'echarts'
import store from './store'
import {postRequest, putFileAttach} from "./utils/api";
import {putRequest} from "./utils/api";
import {getRequest} from "./utils/api";
import {deleteRequest} from "./utils/api";
import {initMenu} from "./utils/menus";
import {downLoadRequest} from "@/utils/download";

Vue.config.productionTip = false
//插件形式使用
Vue.prototype.$echarts=echarts
Vue.prototype.$postRequest=postRequest
Vue.prototype.$putRequest=putRequest
Vue.prototype.$getRequest=getRequest
Vue.prototype.$deleteRequest=deleteRequest
Vue.prototype.$downLoadRequest=downLoadRequest
Vue.prototype.$putFileAttach=putFileAttach
import message from '@/utils/optimizePop.js'

Vue.use(ElementUI);
Vue.prototype.$message = message
router.beforeEach((to, from, next)=>{
  if(window.sessionStorage.getItem("tokenStr")){
    initMenu(router,store)
    if(!window.sessionStorage.getItem("user")){
      return getRequest('/admin/info').then(resp=>{
        if(resp){
          //存入用户信息
          console.log(resp);
          window.sessionStorage.setItem("user",JSON.stringify(resp));
          store.commit('INIT_ADMIN',resp);
          next();
        }
      })

    }
    next();
  }else{
    //next({path:"/"});
    next();
  }
})
new Vue({
  router,
  store,
  render: h => h(App),
}).$mount('#app')
